Ext.onReady(function(){ 

Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = 'under';


var ftpParamStore=new Ext.data.Store({ 
proxy:new Ext.data.HttpProxy({
url:'showType.do?type=FTPParam',
method:'GET'
}), 
reader:new Ext.data.JsonReader({ },[
{name:'name'}, 
{name:'code'}
]) ,
autoLoad: true
}); 

//债项详情
var addForm = new Ext.form.FormPanel({ 
id: 'addForm', 
title:'风险定价',
renderTo:"form",
height: 250, 
//样式 
bodyStyle: 'margin:5px;text-align:left;padding:5px 60px;', 
frame: true, 
xtype: 'filedset', 
labelWidth: 140, 
items: 
[ 
{ xtype: 'fieldset', 
title:'风险定价信息', 
collapsible: true, 
autoHeight: true, 
autoWidth: true, 
items: 
[
 {
	 layout : "form",
     items : [{
  	   xtype: 'textfield', 
  		id:'debtNo',
  		name: 'debtNo', 
  		fieldLabel: '债项流水号', 
  		readOnly:true,
  		hidden:true,
  		width: 200
}
]
 },
{
	layout:"column",
	items:[{
		columnWidth : .5, // 该列有整行中所占百分比
	           layout : "form",
	           items : [{
	        	   xtype: 'textfield', 
	        		id:'debtId',
	        		name: 'debtId', 
	        		fieldLabel: '债项编号', 
	        		readOnly:true,
	        		width: 200
	}
	]},{
		columnWidth : .5, // 该列有整行中所占百分比
	           layout : "form",
	           items : [{
	        	   xtype: 'textfield', 
	       		id:'debtBalance',
	       		name: 'debtBalance', 
	       		fieldLabel: '贷款余额（元）', 
	       		readOnly:true,
	       		width: 200 
	}
	]} 
	]},

	{layout:"column",
	items:[{
		columnWidth : .5, // 该列有整行中所占百分比
	           layout : "form",
	           items : [{
	xtype: 'textfield', 
		id:'ec',
		name: 'ec', 
		fieldLabel: '合同金额（元）', 
		allowBlank: false, 
		readOnly:true,
		width: 200
	}
	]},{
		columnWidth : .5, // 该列有整行中所占百分比
	           layout : "form",
	           items : [{
	        	   xtype: 'textfield', 
		       		id:'el',
		       		name: 'el', 
		       		fieldLabel: '预期损失EL（元）', 
		       		allowBlank: false, 
		       		readOnly:true,
		       		width: 200 
	}
	]} 
	]},
{
	layout:"column",
	items:[{
		columnWidth : .5, // 该列有整行中所占百分比
	           layout : "form",
	           items : [{
	        	   xtype: 'combo', 
		 			  id: 'debtTimeLimit',
		              store :ftpParamStore,
		              fieldLabel: '贷款期限',
		              valueField : 'name',
		              displayField : 'code',
		              emptyText : '请选择...',
		              allowBlank : false,
		              editable: false,
		              typeAhead : true,
		              width: 200,
		              mode:'local', 
		              hiddenName:'debtTimeLimit',
		              triggerAction : 'all',
		              selectOnFocus : true,
		              listeners:{
		              	select : function(combo, record,index){
		              		Ext.getCmp('financeCost').setValue(combo.value); 
		              	}  
		              } 
	          
	}
	]},{
		columnWidth : .5, // 该列有整行中所占百分比
	           layout : "form",
	           items : [{
	        	   xtype: 'textfield', 
	        		id:'financeCost',
	        		name: 'financeCost', 
	        		fieldLabel: '资金成本率FTP（%）', 
	        		allowBlank: false,
	        		readOnly:true,
	        		regex:/^[0-9]+\.{0,1}[0-9]{0,2}$/,
	        	 	regexText:'只能输入整数或小数！' , 
	        		emptyText: '必填', 
	        		blankText: '资金成本不能为空', 
	        		width: 200
	}
	]} 
	]},

	{layout:"column",
	items:[{
		columnWidth : .5, // 该列有整行中所占百分比
	           layout : "form",
	           items : [{
	xtype: 'textfield', 
		id:'operateCost',
		name: 'operateCost', 
		fieldLabel: '运营成本率（%）', 
		allowBlank: false, 
		regex:/^[0-9]+\.{0,1}[0-9]{0,2}$/,
	 	regexText:'只能输入整数或小数！' , 
		emptyText: '必填', 
		blankText: '经营成本不能为空', 
		width: 200
	}
	]},{
		columnWidth : .5, // 该列有整行中所占百分比
	           layout : "form",
	           items : [{
	xtype: 'textfield', 
		id:'busiTax',
		name: 'busiTax', 
		fieldLabel: '营业税及附加率（%）', 
		allowBlank: false, 
		regex:/^[0-9]+\.{0,1}[0-9]{0,2}$/,
	 	regexText:'只能输入整数或小数！' , 
		emptyText: '必填', 
		blankText: '营业税不能为空', 
		width: 200
	}
	]} 
	]},

	{layout:"column",
	items:[{
		columnWidth : .5, // 该列有整行中所占百分比
	           layout : "form",
	           items : [{
	        		xtype: 'textfield', 
	        		id:'roc',
	        		name: 'roc', 
	        		fieldLabel: '资本回报要求（%）', 
	        		allowBlank: false, 
	        		regex:/^[0-9]+\.{0,1}[0-9]{0,2}$/,
	        	 	regexText:'只能输入整数或小数！' , 
	        		emptyText: '必填', 
	        		blankText: '资本回报要求不能为空', 
	        		width: 200
	}
	]},{
		columnWidth : .5, // 该列有整行中所占百分比
	           layout : "form",
	           items : [{
	        	   xtype: 'textfield', 
		       		id:'debtRate',
		       		name: 'debtRate', 
		       		fieldLabel: '贷款利率（%）', 
		       		allowBlank: false, 
		       		regex:/^[0-9]+\.{0,1}[0-9]{0,2}$/,
		       	 	regexText:'只能输入整数或小数！' , 
		       		emptyText: '必填', 
		       		blankText: '贷款利率要求不能为空', 
		       		width: 200
	}
	]} 
	]},

] 
}],
buttonAlign:'right',
buttons: 
[  

{ text: '测算', handler: editFunction },
] 
});

//结果表单
resultForm = new Ext.form.FormPanel({ 
id: 'resultForm', 
height: 130,
renderTo:"result",
//样式 
bodyStyle: 'margin:5px;text-align:left;padding:5px 60px;', 
frame: true, 
xtype: 'filedset', 
labelWidth: 140, 
items: 
[ { xtype: 'fieldset', 
title: '计算结果', 
collapsible: true, 
autoHeight: true, 
autoWidth: true, 
items: 
[ 
{layout:"column",
items:[{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
xtype: 'textfield', 
	id:'raroc',
	name: 'raroc', 
	fieldLabel: '风险调整回报RAROC（%）', 
	readOnly:true,
	width: 200
}
]},{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
xtype: 'textfield', 
	id:'riskPrice',
	name: 'riskPrice', 
	fieldLabel: '建议最低贷款利率（%）', 
	readOnly:true,
	width: 200
}
]} 
]}
] 
}],
buttonAlign:'right',
buttons: 
[  
{ text: '保存', handler:saveDebtRating },
{ text: '重新计算', handler:returnDebtRating }
],
});

//表单加载数据
addForm.form.load({  
    waitMsg : '正在加载数据请稍后',
    waitTitle : '提示',
    url : 'riskApp/getPriceRaroc.do', 
    method:'post',
    success:function(form,action){
    	Ext.getCmp("raroc").setValue(action.result.data.raroc);
		Ext.getCmp("riskPrice").setValue(action.result.data.riskPrice);
    },  
    failure:function(form,action){
		//window.location.href="view/obligation/DebtGuaranteeInfo.jsp";
    }  
});

function editFunction(){

	if(addForm.form.isValid()){
		addForm.form.doAction('submit', { 
			url : 'riskApp/calculatePriceRaroc.do', 
			method : 'post', 
			success : function(form, action) {
				Ext.getCmp("raroc").setValue(action.result.data.raroc);
	    		Ext.getCmp("riskPrice").setValue(action.result.data.riskPrice);
				
				Ext.Msg.alert('提示', '计算成功！'); 		
			}, 
			failure : function() { 
				Ext.Msg.alert('提示', '计算失败！'); 
				
			} 
		}); 
	}
}



function returnDebtRating(){

	if(addForm.form.isValid()){
		addForm.form.doAction('submit', { 
			url : 'riskApp/calculatePriceRaroc.do', 
			method : 'post', 
			success : function(form, action) {
				Ext.getCmp("raroc").setValue(action.result.data.raroc);
	    		Ext.getCmp("riskPrice").setValue(action.result.data.riskPrice);
				
				Ext.Msg.alert('提示', '计算成功！'); 		
			}, 
			failure : function() { 
				Ext.Msg.alert('提示', '计算失败！'); 
				
			} 
		}); 
	}
}

function saveDebtRating(){

	if(addForm.form.isValid()){
		addForm.form.doAction('submit', { 
			url : 'riskApp/savePriceRaroc.do', 
			method : 'post', 
			success : function(form, action) {
				Ext.getCmp("raroc").setValue(action.result.data.raroc);
	    		Ext.getCmp("riskPrice").setValue(action.result.data.riskPrice);
				
				Ext.Msg.alert('提示', '保存成功！'); 		
			}, 
			failure : function() { 
				Ext.Msg.alert('提示', '保存失败！'); 
				
			} 
		}); 
	}
}       
}); 